package GUI;

import java.awt.Rectangle;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
/**
 * This class use for show and update Section details. 
 * @author ido
 * @author michael
 * @author matan
 * @author sharon
 */
public class CategoryManagementForm extends JFrame
{
	
	private static final long serialVersionUID = 1L;
	private JButton addtypeButton = null;
	private JButton addsectionButton = null;
	private JButton addTypeToSectionButton = null;
	private JButton addProductToTypeButton = null;
	private JPanel jContentPane = null;
	private CategoryUpdateForm categoryupdateform = null;
	private TypeUpdateForm typeupdateForm = null;
	private AddProductToTypeForm addproducTotypeForm = null;
	private AddTypeToCategoryForm addtypetocategoryForm = null;
	
	/**
	 * This is the default constructor
	 */
	public CategoryManagementForm() 
	{
		super();
		initialize();		
	}
	
	/**
	 * This method initializes ProductForm
	 */
	private void initialize() 
	{
		categoryupdateform = new CategoryUpdateForm();
		typeupdateForm = new TypeUpdateForm();
		addproducTotypeForm = new AddProductToTypeForm();
		addtypetocategoryForm = new AddTypeToCategoryForm();
		
		typeupdateForm.getCancelButton().addActionListener(new java.awt.event.ActionListener() 
		{
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				setSize(300, 200);
				setTitle("Section Menegment");
				typeupdateForm.restore();
				setContentPane(getJContentPane());					
			}	
		});
		
		categoryupdateform.getCancelButton().addActionListener(new java.awt.event.ActionListener() 
		{
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				setSize(300, 200);
				setTitle("Section Menegment");
				categoryupdateform.restore();
				setContentPane(getJContentPane());					
			}	
		});
		
		addproducTotypeForm.getCancelButton().addActionListener(new java.awt.event.ActionListener() 
		{
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				setSize(300, 200);
				setTitle("Section Menegment");
				addproducTotypeForm.restore();
				setContentPane(getJContentPane());					
			}	
		});
		
		addtypetocategoryForm.getCancelButton().addActionListener(new java.awt.event.ActionListener() 
		{
			public void actionPerformed(java.awt.event.ActionEvent e) 
			{
				setSize(300, 200);
				setTitle("Section Menegment");
				addtypetocategoryForm.restore();
				setContentPane(getJContentPane());					
			}	
		});
		this.setContentPane(getJContentPane());
		this.setTitle("Section Menegment");
		this.setSize(300, 200);
		this.setResizable(false);
	}
	
	private JPanel getJContentPane() 
	{
		if (jContentPane == null) 
		{
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			
			jContentPane.setLayout(null);
			jContentPane.add(getAddTypeButton() ,null);	
			jContentPane.add(getAddSectionButton() ,null);	
			jContentPane.add(getAddTypeToSectionButton() ,null);	
			jContentPane.add(getAddProductToTypeButton() ,null);				
		}
		return jContentPane;		
	}
	
	/**
	 * This method initializes addtypeButton	
	 */
	private JButton getAddTypeButton() 
	{
		if (addtypeButton == null) 
		{
			addtypeButton = new JButton();
			addtypeButton.setBounds(new Rectangle(20, 20, 200, 29));
			addtypeButton.setText("Add/Update type");
			addtypeButton.addActionListener(new java.awt.event.ActionListener() 
			{
				public void actionPerformed(java.awt.event.ActionEvent e) 
				{
					setSize(450, 250);
					setTitle("Add/Update type");
					typeupdateForm.updateForm();	
					setContentPane(typeupdateForm);					
				}	
			});
		}
		return addtypeButton;
	}
	
	/**
	 * This method initializes addsectionButton	
	 */
	private JButton getAddSectionButton() 
	{
		if (addsectionButton == null) 
		{
			addsectionButton = new JButton();
			addsectionButton.setBounds(new Rectangle(20, 50, 200, 29));
			addsectionButton.setText("Add/Update section");
			addsectionButton.addActionListener(new java.awt.event.ActionListener() 
			{
				public void actionPerformed(java.awt.event.ActionEvent e) 
				{
					setSize(450, 250);
					setTitle("Add/Update section");
					categoryupdateform.updateForm();	
					setContentPane(categoryupdateform);					
				}	
			});
		}
		return addsectionButton;
	}
	
	/**
	 * This method initializes addTypeToSectionButton	
	 */
	private JButton getAddTypeToSectionButton() 
	{
		if (addTypeToSectionButton == null) 
		{
			addTypeToSectionButton = new JButton();
			addTypeToSectionButton.setBounds(new Rectangle(20, 80, 200, 29));
			addTypeToSectionButton.setText("Add type to section");
			addTypeToSectionButton.addActionListener(new java.awt.event.ActionListener() 
			{
				public void actionPerformed(java.awt.event.ActionEvent e) 
				{
					setSize(450, 250);
					setTitle("Add type to section");
					addtypetocategoryForm.updateForm();
					setContentPane(addtypetocategoryForm);						
				}	
			});
		}
		return addTypeToSectionButton;
	}
	
	/**
	 * This method initializes addProductToTypeButton	
	 */
	private JButton getAddProductToTypeButton() 
	{
		if (addProductToTypeButton == null) 
		{
			addProductToTypeButton = new JButton();
			addProductToTypeButton.setBounds(new Rectangle(20, 110, 200, 29));
			addProductToTypeButton.setText("Add product to type");
			addProductToTypeButton.addActionListener(new java.awt.event.ActionListener() 
			{
				public void actionPerformed(java.awt.event.ActionEvent e) 
				{
					setSize(600, 250);
					setTitle("Add/Remove product to type");
					addproducTotypeForm.updateForm();
					setContentPane(addproducTotypeForm);										
				}	
			});
		}
		return addProductToTypeButton;
	}
	
	
}
